package greate.project;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

@EnableAsync
@SpringBootApplication
public class EventApplication {


    public static void main(String[] args) {
        SpringApplication.run(EventApplication.class, args);
    }

    @Bean(name = "asyncExecutorService")
    public ExecutorService asyncExecutorService(){
        AtomicInteger atomicInteger = new AtomicInteger(0);
        return new ThreadPoolExecutor(
                10,
                10,
                1000,
                TimeUnit.DAYS,
                new LinkedBlockingDeque<>(),
                r -> new Thread(r , "async-" + atomicInteger.getAndIncrement()),
                new ThreadPoolExecutor.AbortPolicy());
    }

}
